package com.haoshuang.zhouzhoubang.ui.vm

import androidx.lifecycle.rxLifeScope
import com.haoshuang.zhouzhoubang.base.request
import com.haoshuang.zhouzhoubang.config.URLConstants
import com.haoshuang.zhouzhoubang.model.bean.InviteServiceBean
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData

class FriendInvitationViewModel : BaseViewModel() {
    val inviteFriendsData = StatefulMutableLiveData<InviteServiceBean>()
    /** 邀请好友API请求 */
    fun inviteFriends(vararg params: Pair<String,Any?>) {
        rxLifeScope.launch {
            rxLifeScope.launch {
                request<InviteServiceBean>(
                    URLConstants.YaoQingShiFu,*params,
                    onStart = {
                        inviteFriendsData.value = StateData.Loading
                    },
                    onError = { code, msg ->
                        inviteFriendsData.value = StateData.Error(code, msg)
                    },
                    onSuccess = {
                        inviteFriendsData.value = StateData.Success(it)
                    })
            }
        }
    }

}